package com.design.movieticket.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.design.movieticket.common.base.constant.Result;
import com.design.movieticket.common.base.constant.ResultStatus;
import com.design.movieticket.common.dto.XPage;
import com.design.movieticket.entity.Role;
import com.design.movieticket.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Slf4j
@Api(tags = "角色模块")
@RestController
@RequestMapping("/role")
public class RoleController {
    @Resource
    private RoleService roleService;

    /** 分页查询 */
    @ApiOperation("角色信息分页展示")
    @GetMapping("/list/page")
    public Result findRoleInfoListByPage(Role role, XPage<Void> page) {
        IPage<Role> roleInfoList = roleService.page(XPage.toIPage(page), roleService.buildQuery(role));
        return new Result(roleInfoList, ResultStatus.REQUEST_SUCCESS.getMsg(),ResultStatus.REQUEST_SUCCESS.getCode());
    }

    /** 新增或更新角色数据 */
    @ApiOperation("新增或更新角色数据")
    @PostMapping("/addOrUpdate")
    public Result addOrEditRoleInfo(Role role) {
        System.out.println(" role"+role);
        roleService.addOrUpdateRoleInfo(role);
        return new Result(ResultStatus.SAVE_SUCCESS.getMsg(),ResultStatus.SAVE_SUCCESS.getCode());
    }

    /** 获取角色信息 */
    @ApiOperation("获取角色信息详情")
    @GetMapping("/getRoleDetail/{id}")
    public Result getRoleInfoDetail(@PathVariable long id){
        return new Result(roleService.getRoleDetail(id),ResultStatus.REQUEST_SUCCESS.getMsg(),ResultStatus.REQUEST_SUCCESS.getCode());
    }

    /** 删除角色信息 */
    @ApiOperation("删除角色信息")
    @PostMapping("/delRoleById/{id}")
    public Result delRoleInfoById(@PathVariable long id){
        roleService.delRoleById(id);
        return new Result(ResultStatus.DELETE_SUCCESS.getMsg(),ResultStatus.DELETE_SUCCESS.getCode());
    }
}
